﻿using System;
using System.Collections.Generic;
using System.Linq;
using Complaint.Models.Dtos.Validators;

namespace Complaint.Models.Dtos
{
    public partial class Organisation : IEntity
    {
        public Organisation()
        {
            DateAdded = DateTime.Now;
        }

        #region Implementation of IEntity

        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(Name))
                yield return new RuleViolation("Name is required", "Name");

            //if (String.IsNullOrEmpty(CustomerCareEmail))
            //{
            //    yield return new RuleViolation("Email is required", "CustomerCareEmail");
            //}

            if (!String.IsNullOrEmpty(CustomerCareEmail))
            {
                if (!EmailValidator.IsValidEmail(CustomerCareEmail))
                    yield return new RuleViolation("Please enter a valid email address", "CustomerCareEmail");
            }

            if (Category == null || Category.Count == 0)
            {
                yield return new RuleViolation("At least one category is required", "categoryIDs");
            }

            if (String.IsNullOrEmpty(Tel))
                if (!PhoneValidator.IsValidNumber(Tel, Country))
                    yield return new RuleViolation("Phone# does not match country", "Tel");
        }

        #endregion
    }
}